const express = require("express");
const cors = require("cors");
const apiRoutes = require('./router/api'); // 确保路径正确

const app = express();

app.set("secret", "b7afb7f6b6fab6f");

app.use(cors());
app.use(express.json());
app.use("/uploads", express.static(__dirname + "/uploads"));

require("./plugins/db")(app);
require("./router/admin")(app);
require("./router/web")(app);


app.use(express.json()); // 解析JSON请求体
app.use('/api', apiRoutes); // 将 /api 前缀分配给所有API路由

const PORT = process.env.PORT ? Number(process.env.PORT) : 3000;
app.listen(PORT, () => {
  console.log(`http://localhost:${PORT} 服务器已就绪！`);
});

